/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software. 
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package com.example.soscall.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.soscall.R;
import com.example.soscall.utils.TimeUtil;


public class RescueView extends FrameLayout {

    private static final String TAG = RescueView.class.getSimpleName();

    private TextView rescueTimeTextView;
    private int seconds;
    private Context mContext;

    public RescueView(Context context) {
        super(context);
        this.mContext = context;
        LayoutInflater.from(context).inflate(R.layout.rescue_view, this, true);
        rescueTimeTextView = findViewById(R.id.tv_rescue_time);
    }

    public void updateTime(int time) {
        this.seconds = time;
        mHandler.removeMessages(0);
        mHandler.sendEmptyMessage(0);
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @SuppressLint("SetTextI18n")
        @Override
        public void handleMessage(Message msg) {
            rescueTimeTextView.setText(mContext.getString(R.string.estimated_arrive_time) + " " + TimeUtil.formatCallTime(seconds));
            if (seconds > 0) {
                seconds = seconds - 1;
                mHandler.sendEmptyMessageDelayed(0, 1000);
            } else {
//                WindowUtils.dismissRescueWindow(mContext, false);
            }
        }
    };


}
